package com.netty.bfport.http.controller;

import com.netty.bfport.http.common.base.BaseResponse;
import com.netty.bfport.http.common.base.BaseResponseVO;
import com.netty.bfport.http.service.PersonInfoService;
import com.netty.bfport.http.service.UserMsgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;

/**
 * @Author: zhaoyang05
 * @Data: 2022/3/23 10:21
 * @Description
 */
@RestController
@RequestMapping("/person")
public class PersonInfoController {
    @Resource
    PersonInfoService personInfoService;
    @Resource
    UserMsgService userMsgService;

    /**
     * 用户列表查询
     *
     * @return*/
    @GetMapping("/list")
    public BaseResponseVO userList(@RequestParam(value = "name",required=false)String name, @RequestParam(value = "telephone",required=false)String telephone,@RequestParam("page")Integer page,@RequestParam("size")Integer size){
         return  BaseResponse.setResultSuccess(personInfoService.userList(name, telephone, page, size));
    }

//    /**
//     * 用户添加
//     * */
//    @PostMapping("/add")
//    public BaseResponseVO userAdd(@Validated @RequestBody TUserDTO tUserDTO){
//        return  BaseResponse.setResultSuccess(personInfoService.userAdd(tUserDTO));
//    }
//
//
//    /**
//     * 修改用户个人信息
//     * */
//    @PostMapping("/up")
////    public BaseResponseVO userUp(@Validated @RequestBody TUserDTO tUserDTO){
//    public BaseResponseVO userUp(@Validated @RequestBody TUserDTO tUserDTO){
//        return  BaseResponse.setResultSuccess(personInfoService.userUp(tUserDTO));
//    }

    /**
     * 获取用户个人信息
     * */
    @GetMapping("/info")
    public BaseResponseVO userInfo(@RequestParam String userId){
        return  BaseResponse.setResultSuccess(userMsgService.findUserInfo(userId));
    }

    @GetMapping("/info_list")
    public BaseResponseVO healthyList(@RequestParam(value = "userId")String userId,@RequestParam(value = "time",required = false) Long time) throws IOException {
        Date times;
        if (time==null){
            times = new Date();
        }else {
            times = new Date(time);
        }
        return BaseResponse.setResultSuccess(personInfoService.healthyList(userId, times));
    }

}
